const express=require('express');
const mysql=require('mysql');
const common=require('../../libs/common.js');
const urlobj=require('url');
const multer=require('multer');
const multerObj=multer({dest:'../../www/upload'});
const pathLib=require('path');
const fs=require('fs');
//链接数据库
var db=mysql.createPool({
  host:'localhost',
  user:'root',
  password:'',
  database:'leasedb'
});
module.exports = function() {
  var router = express.Router();

  //根据一级商品id查询所有二级商品的分类
  router.use('/DetailsOfClassification', function(req, res){
    db.query("SELECT * FROM classb,classa WHERE classb.classAId=classa .classAId and classa .classAId="+req.body.classAId+"",function(err,data){
      if(err)
      {
        res.send('{"status":"400"}').end();//查询出错
      }
      else
      {
        if(data.length==0)
        {
          res.send('{"status":"300"}').end();//没有数据
        }else
        {
          res.send('{"status":"200","msg":'+JSON.stringify(data)+'}').end();
        }
      }
    });
 });

//动态查询分类
  router.use('/classBlistfotdetails', function(req, res) {

    for(i=0;i<sss.length;i++)
    {
      db.query("SELECT * FROM classa, classb, classc,userinfo WHERE classa.classAId = classb.classAId AND classb.classBId = classc.classBId AND userinfo.userId = classc.userId AND  classb.classBId ="+ +i+" ORDER BY `classc`.`classCTime` DESC",function(err,data){
        if(err)
        {
          res.send('{"status":"400"}').end();
        }
        else
        {
          res.send('{"status":"200","msg":'+JSON.stringify(data)+'}').end();
        }
      });
    }

  });


  return router;
}
